using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GridView : Graphic
{
    public PixelCanvas pixelCanvas;

    [Space]

    public float lineSize;
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        var (bl, tr) = UIMeshHelper.CalculateCorners(rectTransform);
        vh.Clear();
        var xStep = rectTransform.rect.width / pixelCanvas.Width;
        var yStep = rectTransform.rect.height / pixelCanvas.Height;
        for (int i = 0; i <= pixelCanvas.Height; i++)
        {
            UIMeshHelper.DrawLine(vh, new Vector2(bl.x, bl.y + i * yStep), new Vector2(tr.x, bl.y + i * yStep), lineSize, color);
        }

        for (int i = 0; i <= pixelCanvas.Width; i++)
        {
            UIMeshHelper.DrawLine(vh, new Vector2(bl.x + i * xStep, bl.y), new Vector2(bl.x + i * xStep, tr.y), lineSize, color);
        }
    }
}
